package com.financial.service.integralpay.controller;


import com.financial.service.integralpay.service.FinancialIntegralAgencyPayService;
import com.financial.service.integralpay.utils.balanceutils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/gyIntegralAgencypay")
public class FinancialIntegralAgencyPayController {
    @Autowired
    FinancialIntegralAgencyPayService integralAgencyPayService;
    public static final Logger logger = LoggerFactory.getLogger(FinancialIntegralAgencyPayController.class);
    @PostMapping("/integralAgencypay")
    public String integralAgencypay(@RequestParam Map<String,Object> reqMap){
        Map returnMap = new HashMap();
        try {
            Map<String, Object> map = integralAgencyPayService.integralAgencypay(reqMap);
            logger.info("积分代付调用银盛返回"+map);
            if (map.get("code").toString().equals("10000")&& map.get("trade_status").equals("TRADE_ACCEPT_SUCCESS")){
                returnMap.put("agentcyStatus",true);
            }else{
                returnMap.put("agentcyStatus",false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("金融中心积分代付调用银盛代付接口失败 :{}",e.getMessage());
        }
        logger.info("调用积分代付结果返回优店"+JsonUtils.objectToJson(returnMap));
        return JsonUtils.objectToJson(returnMap);
    }

    /**
     *  积分代付主动查询
     * @param requestMap
     * @return
     */
    @PostMapping("/integralAgencypayQuery")
    public Map<String,Object> integralAgencypayQuery(@RequestParam Map<String,Object> requestMap){

        return integralAgencyPayService.integralQuery(requestMap);
    }

}
